package com.kevinwu.zookeepertask.taskone.service;

import java.util.Timer;

public class MyTimer {

    private static int count = 0;

    public static void setCount(int count) {
        MyTimer.count = count;
    }

    public static void doCount(){
        Timer timer = new Timer();
        timer.schedule(new MyTask(), 1000, 1000);//在1秒后执行此任务,每次间隔1秒
    }

    static class MyTask extends java.util.TimerTask{
        @Override
        public void run() {
            System.out.println("计数器值："+count);
            count ++;
            if(count > 5){//执行了5次 每次1秒 相当于5秒内未响应
                count = 0;
                try {
                    UserServiceImpl.clearResponseNode();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
